package com.example.demo.Controller;

import com.example.demo.Service.UserService;
import com.example.demo.entity.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

@Controller
public class xuexi {
    private UserService Us;

    @Autowired
    public void setUs(UserService us) {
        Us = us;
    }

    @GetMapping("/")
    public String list(Map<Object, Object> map, Integer pageNum, Integer pageSize, User user) {
        pageNum = StringUtils.isEmpty(pageNum) ? 1 : pageNum;
        pageSize = StringUtils.isEmpty(pageSize) ? 5 : pageSize;
        PageHelper.startPage(pageNum, pageSize);
        List<User> list = Us.list(user);
        list.forEach(System.out::println);
        PageInfo<User> objectPageInfo = new PageInfo<>(list);
        map.put("user", objectPageInfo);
        return "login";
    }
}
